package com.czh.www.domain;


import com.czh.www.gui.IUserListGui;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SystemVar {
    public static Semaphore PACKET_QUEUE_FULL = new Semaphore(0);
    public static Semaphore PACKET_QUEUE_EMPTY = new Semaphore(100);
    public static String USER_NAME;
    public static String HOST_NAME;
    private static List<UsersVo> USER_LIST;
    private static IUserListGui userListGui;
    public static String USER_HOME;
    public static String DEFAULT_CHARACT;
    public static String LINE_SEPARATOR;
    public static String FILE_SEPARATOR;
    public static char OS;

    public SystemVar() {
    }

    public static void init() {
        USER_NAME = System.getProperty("user.name");
        USER_HOME = System.getProperty("user.home");
        LINE_SEPARATOR = System.getProperty("line.separator");
        FILE_SEPARATOR = System.getProperty("file.separator");
        if (System.getProperty("os.name").equalsIgnoreCase("linux")) {
            OS = 1;
        } else if (System.getProperty("os.name").equalsIgnoreCase("window")) {
            OS = 0;
        } else {
            OS = 2;
        }

        try {
            HOST_NAME = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException var1) {
            HOST_NAME = "";
            Logger.getLogger(SystemVar.class.getName()).log(Level.SEVERE, (String) null, var1);
        }

        DEFAULT_CHARACT = "GBK";
        USER_LIST = new ArrayList();
    }

    public static List<UsersVo> getUserList() {
        return USER_LIST;
    }

    public static void setUserList(List<UsersVo> userList) {
        USER_LIST = userList;
    }

    public static synchronized boolean addUsers(UsersVo user) {
        for (int i = 0; i < USER_LIST.size(); ++i) {
            if (((UsersVo) USER_LIST.get(i)).getIp().equals(user.getIp())) {
                USER_LIST.set(i, user);
                return false;
            }
        }

        USER_LIST.add(user);
        return true;
    }

    public static void clearUsers() {
        USER_LIST.clear();
    }

    public static IUserListGui getUserListGui() {
        return userListGui;
    }

    public static void setUserListGui(IUserListGui userListGui) {
        SystemVar.userListGui = userListGui;
    }

    public static void main(String[] args) {
        try {
            System.out.println(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException var2) {
            Logger.getLogger(SystemVar.class.getName()).log(Level.SEVERE, (String) null, var2);
        }

    }

    public static int getUserIndex(String ip) {
        for (int i = 0; i < USER_LIST.size(); ++i) {
            if (((UsersVo) USER_LIST.get(i)).getIp().equals(ip)) {
                return i;
            }
        }

        return 0;
    }
}
